package com.example.demo.core.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.handler.MappedInterceptor;

/**
 * 将拦截器组件注册至mvc中去
 * @author kaixuan.xu
 * @version 1.0.0
 * @time 2019/2/17 16:55
 * @description
 */
@Configuration
public class RegisterInterceptor implements WebMvcConfigurer {

  /**
   * Add Spring MVC lifecycle interceptors for pre- and post-processing of controller method
   * invocations. Interceptors can be registered to apply to all requests or be limited to a subset
   * of URL patterns.
   * <p><strong>Note</strong> that interceptors registered here only apply to
   * controllers and not to resource handler requests. To intercept requests for static resources
   * either declare a {@link MappedInterceptor MappedInterceptor} bean or switch to advanced
   * configuration mode by extending {@link WebMvcConfigurationSupport WebMvcConfigurationSupport}
   * and then override {@code resourceHandlerMapping}.
   */
  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    CustomInterceptor customInterceptor = new CustomInterceptor();
    CustomInterceptor1 customInterceptor1 = new CustomInterceptor1();
   // registry.addInterceptor(customInterceptor);
   // registry.addInterceptor(customInterceptor1);
  }
}
